import historyItem from './historyItem';

class historyList {
  private historyList: historyItem[] = [];
  // data = ['{"author":'wuming123',"lastDate":'2020-3-24 20:48'}']
  public parse(value: string): historyItem {
    let data = JSON.parse(value);
    return new historyItem(data.author, data.lastDate);
  }
  public parseArr(value: string[]): historyItem[] {
    let arr: historyItem[] = [];
    value.forEach(e => {
      arr.push(this.parse(e));
    });
    return arr;
  }
  public stringify(value: historyItem): string {
    return `{author:'${value.getLastEditAuthor()},lastDate:'${value.getLastEditDate()}'}`;
  }
  public stringifyArr(value: historyItem[]): string[] {
    let arr: string[] = [];
    value.forEach(e => {
      arr.push(this.stringify(e));
    });
    return arr;
  }
  public getHistoryList(): historyItem[] {
    return this.historyList;
  }
  public getHistory(value: number): historyItem {
    return this.historyList[value];
  }
  public addHistoryItem(value: historyItem) {
    this.historyList.push(value);
  }
  constructor(value: string[]) {
    value.forEach(e => {
      this.historyList.push(this.parse(e));
    });
  }
}

export default historyList;
